package test.scala

import main.scala.Parser
import main.scala.AST._

import org.scalatest.FunSuite

class TestParser extends FunSuite with Parser {
  
  test("var") {
    parseAll(start, "x" + "\n") match{
      case Success (e, in) => 
        assert(e == Var("x"));
      case f => fail("fail: " + f)
    }
  }

  test("mul") {
	  parseAll(start, "x*y" + "\n") match{
	  case Success (e, in) => 
	  assert(e == BMul(Var("x"),Var("y")));
	  case f => fail("fail: " + f)
	  }
  }

  test("pow") {
	  parseAll(start, "x^y" + "\n") match{
	  case Success (e, in) => 
	  assert(e ==  Pow(Var("x"),Var("y")));
	  case f => fail("fail: " + f)
	  }
  }

  test("add") {
	  parseAll(start, "x+y" + "\n") match{
	  case Success (e, in) => 
	  assert(e == BAdd(Var("x"),Var("y")));
	  case f => fail("fail: " + f)
	  }
  }
  
  test("sub") {
	  parseAll(start, "x-y" + "\n") match{
	  case Success (e, in) => 
	  assert(e == BSub(Var("x"),Var("y")));
	  case f => fail("fail: " + f)
	  }
  }
  
  test("add-mul-pow-sub-mod") {
    parseAll(start, "x^2 + 3 + y + 10*x - z - k - a + 5 % k" + "\n") match{
      case Success (e, in) => 
        assert(e === BAdd(BSub(BSub(BSub(BAdd(BAdd(BAdd(Pow(Var("x"),NumI(2)),NumI(3)),Var("y")),BMul(NumI(10),Var("x"))),Var("z")),Var("k")),Var("a")), Mod(NumI(5),Var("k"))) );
      case f => fail("fail: " + f)
    }
  }

}